import mongoose from "mongoose";

const essaySchema = new mongoose.Schema({
  PagesNume: [{ type: Number, required: true }], // 页码数组
  frontContent: [{ type: mongoose.Schema.Types.Mixed }], // 正面内容
  backContent: [{ type: mongoose.Schema.Types.Mixed }], // 背面内容
});

const bookDataSchema = new mongoose.Schema(
  {
    userId: {
      type: mongoose.Schema.Types.ObjectId,
      required: true,
      ref: "User",
    }, // 用户id
    name: { type: String, required: true }, // 名称
    desc: { type: String }, // 简单语句
    avatar: { type: String }, // 头像链接
    isAvatar: { type: Boolean, default: true }, // 是否显示头像和名称
    essay: [essaySchema], // 整页内容页数据
    bookfront1: { type: String }, // 书本封面正面链接
    bookfront2: { type: String }, // 书本封面背面链接
    bookPage1: { type: String }, // 书本内容页正面链接
    bookPage2: { type: String }, // 书本内容页背面链接
    bookBack: { type: String }, // 书本封底链接
    rotateY: { type: Number, default: 0 }, // 书本旋转角度左右
    rotateX: { type: Number, default: 0 }, // 书本旋转角度上下
    bookTop: { type: Number, default: 0 }, // 书本位置
    bookLeft: { type: Number, default: 0 }, // 书本位置
    transformOrigin: { type: String, default: "left center" }, // 书本打开方向
    color: { type: String, default: "#000000ff" }, // 书本文字颜色
    avatarTop: { type: Number, default: 0 }, // 头像位置
    avatarLeft: { type: Number, default: 0 }, // 头像位置2
    Layers: { type: Number, required: true }, // 图层
  },
  { collection: "BookData" }
);

const BookData = mongoose.model("BookData", bookDataSchema);

export default BookData;
